const { completeRequire } = require("../../utils")
const inflectionMiddleware = require("../../middleware/resource")
const multer = require("multer");
const path = require("path");
const { createStorage } = require("../../utils/upload")
module.exports = ({ app, router }) => {
    completeRequire(__dirname, { app, router })

    // Multer 是一个 node.js 中间件，用于处理 multipart/form-data 类型的表单数据，它主要用于上传文件。
    const upload = multer({
        dest: path.join(__dirname, '/../../uploads'),
        storage: createStorage()
    });
    app.post('/upload', upload.single('file'), async (req, res) => {
        let file = req.file;
        file.url = `http://localhost:3000/uploads/${file.filename}`
        res.send(file);
    })

    app.use("/api/admin/:resource", inflectionMiddleware(), router)
}
